<%@page import="com.metagurukul.metagranth.vo.Answer"%>
<%@page import="com.metagurukul.metagranth.vo.AnswerMetaData"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.metagurukul.metagranth.vo.User"%>
<%@page import="com.metagurukul.metagranth.vo.Tag"%>
<%@page import="com.metagurukul.metagranth.vo.MetaData"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"
	import="com.metagurukul.metagranth.vo.Question"%>
<%@include file="header.jsp"%>
<%
if(session.getAttribute("userType")==null){
	%><script type="text/javascript">window.location='index.jsp'</script><%
}else {
	if(Integer.parseInt(session.getAttribute("userType").toString())!=1){
	%><script type="text/javascript">window.location='access-denied.jsp'</script><%
	}
}
%>

<%
	if(request.getAttribute("metaData")!=null){
		MetaData metaData = (MetaData) request.getAttribute("metaData");
%>
<%
	Question question = metaData.getQuestion();
	ArrayList<Tag> tagList = metaData.getTagList();
	User user = metaData.getUser();
	String dateTime = question.getDateOfPost().toString();
	String date = dateTime.substring(0, 10);
	String time = dateTime.substring(10);
	ArrayList<AnswerMetaData> answerMetaDataList = metaData
			.getAnswerMetaDataList();
%>
<form action="closequestion.do" method="post" id="approveForm" name="approveForm" onsubmit="">
	<table width="90%" border="0" align="center">
		<tr>
			<td colspan="3">&nbsp;</td>
		</tr>
		<tr>
			<td colspan="3" class="question-header">
				<%
					out.print(question.getTitle().substring(0, 1).toUpperCase());

					if (question.getTitle().length() > 1) {
						out.println(question.getTitle().substring(1,
								question.getTitle().length()));
					}
				%>
			</td>
		</tr>
		<tr>
			<td colspan="3" height="50px" valign="top"><hr />
			</td>
		</tr>
		<tr>
			<td colspan="3" class="question-discription">
				<%
					Integer questionRow = (question.getQuestion().length() / 102) + 1;
				%> <textarea rows="<%=questionRow%>" class="code-textarea"
					readonly="readonly"><%=question.getQuestion()%></textarea>
			</td>
		</tr>

		<%
			if (tagList.size() > 0) {
		%>
		<tr>
			<td colspan="3" align="left" valign="bottom" height="50px">
				<%
					for (Tag tag : tagList) {
				%> <a href="searchQuestionByTag.do?tagFilterId=<%=tag.getTagid()%>"
				class="post-tag" title="" rel="tag"><%=tag.getTagName()%></a> <%
 	}
 %>
			</td>
		</tr>
		<%
			}
		%>
		<tr>
			<td align="right" valign="bottom" colspan="3" class="posted">Posted
				By : <%=user.getName()%></td>
		</tr>
		<tr>
			<td align="right" class="posted" colspan="3">Time :<%=time.substring(0, time.length() - 2)%>&nbsp;&nbsp;Date
				: <%=date%></td>
		</tr>
		<tr>
			<td colspan="3" class="question-header"><%=answerMetaDataList.size()%>
				Answers</td>
		</tr>
		<tr>
			<td colspan="3"><hr />
			</td>
		</tr>
		<tr>
			<td colspan="3" height="30px">&nbsp;</td>
		</tr>
		<%
			for (AnswerMetaData answerMetaData : answerMetaDataList) {
				Answer answer = answerMetaData.getAnswer();
				User answeredUser = answerMetaData.getUser();
				String answerDateTime = question.getDateOfPost().toString();
				String answerDate = dateTime.substring(0, 10);
				String answerTime = dateTime.substring(10);
		%>
		<tr>
			<td width="32" valign="middle" colspan="1"><input type="radio"
				name="checkanswer" id="checkanswer1" value="<%=answer.getAid()%>" />
			</td>
			<%
				Integer ansrow = (answer.getAnswer().length() / 102) + 1;
			%>
			<td colspan="2" valign="top" class="question-discription"><textarea
					rows="<%=ansrow%>" class="code-textarea" readonly="readonly"><%=answer.getAnswer()%></textarea>
			</td>
		</tr>

		<tr>
			<td align="left" valign="bottom" colspan="3" height="30px">&nbsp;</td>
		</tr>
		<tr>
			<td align="left" valign="bottom" colspan="3" class="posted">Posted
				By : <%=answeredUser.getName()%></td>
		</tr>
		<tr>
			<td align="left" class="posted" colspan="3" height="40px;"
				valign="top">Time : <%=answerTime.substring(0, answerTime.length() - 2)%>&nbsp;&nbsp;Date
				: <%=answerDate%></td>
		</tr>
		<tr>
			<td colspan="3" style="border-top: 1px dotted #000000;" height="30px"
				valign="middle">&nbsp;</td>
		</tr>

		<%
			}
		%>
		<tr>
			<td colspan="3"><div class="submitdiv">
							<input type="submit" name="submit" value="" class="btn_approve_submit" onclick="return approveAnswerForm()"> 
						</div>
			</td>
		</tr>
	</table>
</form>
<%}else{ %>
<script type="text/javascript">window.location='adminhome.jsp'</script>
<%} %>
<%@include file="footer.jsp"%>